//
//  BaseEmptyCollectionViewCel.swift
//  app
//
//  Created by gy on 2023/9/18.
//

import UIKit

open class BaseEmptyCollectionViewCell: UICollectionViewCell {
    
    var funcBtnHandle: (()->Void)?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        configUI()
    }
    public static func getCellHeight() -> CGFloat {
        return 140 + 60
    }
    public func setInfo(iconName: String, title: String, funBtnTitle: String = "") {
        imgView.image = UIImage(named: iconName)
        promptLabel.text = title
        
        let btnTitle = "前往\(funBtnTitle)授权"
        funcBtn.isHidden = funBtnTitle.count == 0
        funcBtn.setTitle(btnTitle, for: .normal)
        funcBtn.snp.updateConstraints { make in
            make.width.equalTo(btnTitle.widthWithLimit(CGSize(width: CGFloat.greatestFiniteMagnitude, height: 42), font: kSetPingFangRegular(16)) + 34)
            make.top.equalTo(promptLabel.snp.bottom).offset(funBtnTitle.count == 0 ? 0:30)
            make.height.equalTo(funBtnTitle.count == 0 ? 0:38)
        }
    }
    
    // MARK: - UIButtonAction
    @objc func funcBtnAction() {
        guard let handle = funcBtnHandle else { return }
        handle()
    }
    
    // MARK: - configUI
    func configUI() {
        
        backgroundColor = .clear
        
        contentView.addSubview(backView)
        backView.addSubview(imgView)
        imgView.contentMode = .scaleAspectFill
        backView.addSubview(promptLabel)
        backView.addSubview(funcBtn)
        
        backView.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.left.equalTo(16)
            make.right.equalTo(-16)
        }
        imgView.snp.makeConstraints { make in
            make.height.equalTo(60)
            make.top.centerX.equalToSuperview()
        }
        promptLabel.snp.makeConstraints { make in
            make.top.equalTo(imgView.snp.bottom).offset(10)
            make.left.right.centerX.equalToSuperview()
        }
        funcBtn.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.width.equalTo(0)
            make.height.equalTo(38)
            make.top.equalTo(promptLabel.snp.bottom).offset(30)
            make.bottom.equalToSuperview()
        }
        
        funcBtn.addTarget(self, action: #selector(funcBtnAction), for: .touchUpInside)
    }
    public lazy var backView: UIView = {
        let backView = UIView()
        return backView
    }()
    public lazy var imgView = UIImageView()
    public lazy var promptLabel: UILabel = {
        let promptLabel = UILabel()
        promptLabel.font = kSetPingFangRegular(14)
        promptLabel.textColor = UIColor(hex: 0xAEAEAE)
        promptLabel.textAlignment = .center
        return promptLabel
    }()
    public lazy var funcBtn: AppCustomButton = {
        let funcBtn = AppCustomButton()
        funcBtn.backgroundColor = .app_themeColor
        funcBtn.titleLabel?.font = kSetPingFangRegular(16)
        funcBtn.isHidden = true
        funcBtn.layer.cornerRadius = 19
        funcBtn.layer.masksToBounds = true
        return funcBtn
    }()
    
    required public init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
